<!--
 * @Author: 乌日汗 3337511892@qq.com
 * @Date: 2025-09-11 08:39:01
 * @LastEditors: 乌日汗 3337511892@qq.com
 * @LastEditTime: 2025-09-17 15:39:33
 * @FilePath: \大三上 前端\city\src\pages\components\Left1 copy.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div>
        <Title :title="title"></Title>
        <!-- 1.提供图表容器  ref模板引用 类似于id  -->
        <div ref="bottom2" style="height: 150px;margin-top: 10px;"></div>

    </div>
</template>
<script>
import { Sunburst,CirclePacking } from '@antv/g2plot';
//2.引入折线图构造函数 
import { Line } from '@antv/g2plot';
// 引入get请求 @表示src别名 
import { get } from '@/utils/request';
// 引入momentjs
import moment from 'moment';
// import axios from 'axios';
import { mapState } from 'vuex';
export default {
    data() {
        return {
            title: '监测月报',
            params: {
                page: 1,
                pageSize: 100
            },
            // 存放温度数据
            monitorData: [],
            // 创建一个图表实例 
            plot: null
        }
    },
    computed: {
        ...mapState(['ed'])
    },
    // 侦听器 侦听数据 
    watch: {
        ed: {
            handler(n, o) {
                // 根据设备信息重新查询数据 重新渲染图表
                // console.log(n,'11111111111111'); 
                this.params.engineer_id = n.engineer_id;
                this.params.device_id = n.device_id;
                this.getServiceData();
                // 根据最新获取的数据重新渲染图表 
                this.line.changeData(this.serviceData);
            },
            // 深度监听 
            deep: true
        }
    },
    methods: {
        // 封装加载折线图图表函数 
        loadLine() {
            this.plot = new CirclePacking(this.$refs.bottom2, {
                autoFit: true,
                data: {
                    "name": "root",
                    "children": [
                        {
                            "name": "Drama",
                            "value": 1046790
                        },
                        {
                            "name": "Comedy",
                            "value": 1039358
                        },
                        {
                            "name": "Documentary",
                            "value": 461880
                        },
                        {
                            "name": "News",
                            "value": 308136
                        },
                        {
                            "name": "Talk-Show",
                            "value": 270578
                        },
                        {
                            "name": "Action",
                            "value": 226334
                        },
                        {
                            "name": "Animation",
                            "value": 197342
                        },
                        {
                            "name": "Reality-TV",
                            "value": 189739
                        },
                        {
                            "name": "Crime",
                            "value": 175272
                        },
                        {
                            "name": "Family",
                            "value": 150621
                        },
                        {
                            "name": "Short",
                            "value": 138255
                        },
                        {
                            "name": "Adventure",
                            "value": 121216
                        },
                        {
                            "name": "Game-Show",
                            "value": 119912
                        },
                        {
                            "name": "Music",
                            "value": 102488
                        },
                        {
                            "name": "Adult",
                            "value": 90157
                        },
                        {
                            "name": "Biography",
                            "value": 59307
                        },
                        {
                            "name": "Sport",
                            "value": 58999
                        },
                        {
                            "name": "Romance",
                            "value": 52776
                        },
                        {
                            "name": "Horror",
                            "value": 50800
                        },
                        {
                            "name": "Fantasy",
                            "value": 22614
                        },
                        {
                            "name": "Sci-Fi",
                            "value": 22026
                        },
                        {
                            "name": "Thriller",
                            "value": 19706
                        },
                        {
                            "name": "Mystery",
                            "value": 18274
                        },
                        {
                            "name": "History",
                            "value": 16108
                        },
                        {
                            "name": "Western",
                            "value": 12535
                        },
                        {
                            "name": "Musical",
                            "value": 12240
                        },
                        {
                            "name": "War",
                            "value": 1992
                        },
                        {
                            "name": "Film-Noir",
                            "value": 36
                        }
                    ]
                },
                label: false,
                legend: false,
                hierarchyConfig: {
                    sort: (a, b) => b.depth - a.depth,
                },
            });

            this.plot.render();
        },
        // 封装方法获取后端接口的实时数据 
        async getServiceData() {
            let res = await get('/dashboard/pageQueryTodayData', this.params);
            // console.log(res, "获取响应");
            let service = [];
            // 将后端获取的数据设置给tempData 
            res.data.list.forEach((item, index, arr) => {
                // 由于刻度混乱 将第一条数据值设置为15.4 
                arr[0].humidity = 15.4;
                // item表示数组每一项 
                item.insert_time = moment(item.insert_time).format("HH:mm");
                // 由于查询数据密度密集 需要将数据处理 每隔10条数据取一条数据 
                if (index % 10 == 0) {
                    service.push(arr[index])
                }
            });
            this.serviceData = service;
        }
    },
    // 最早获取dom元素的生命周期  图表渲染dom元素
    async mounted() {
        await this.getServiceData();
        this.loadLine();
    }

}


</script>

<style lang="less" scoped></style>